package com.saint.lt.domain;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "teams")
public class Team {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private int id;

	@Column(name = "descr")
	private String descr;

	@ManyToOne(fetch=FetchType.LAZY, targetEntity = User.class)
	@JoinColumn(name="master")
	private User master;

	@ManyToMany(targetEntity = User.class)
	@JoinTable(name = "rel_teams_users", joinColumns = { @JoinColumn(name = "id_team", 
		referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "id_user", 
		referencedColumnName = "username") })
	private List<User> users;

	@OneToMany(mappedBy = "team", targetEntity = Project.class)
	private List<Project> projects;
	
	public List<Project> getProjects() {
		return projects;
	}

	public void setProjects(List<Project> projects) {
		this.projects = projects;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescr() {
		return descr;
	}

	public void setDescr(String descr) {
		this.descr = descr;
	}

	public User getMaster() {
		return master;
	}

	public void setMaster(User master) {
		this.master = master;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
	
}
